package isi_graf;

import java.util.Iterator;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

import isi_ib.barra_trade;
import isi_ib.barras_trade;
import isi_ib.isi_estudios;



///// NO SE USA //////
public class isi_doblelineaChart {
	private XYDataset dataset;
	private JFreeChart chart;
	private ChartPanel chartPanel;
	String titulo;
		
	
	public  isi_doblelineaChart(String titulo_) {
		super();
		dataset=null;
		chart=null;
		chartPanel=null;
		titulo=titulo_;
		
	}
	
	public ChartPanel CreaChart(int recorte_){
		
		dataset = createDataset(recorte_);
		chart = createChart(dataset);
//		Ajusta(double(-1000),+1000);
		chartPanel = new ChartPanel(chart);
		return chartPanel;
	}
	
	private void Ajusta(Double minvalue_,Double maxvalue_){
		if(chart==null) return;
	/*	if(minvalue_==0 && maxvalue_==0){
			minvalue_ = getLowestLow(dataset);
			maxvalue_ = getHighestHigh(dataset);
		}*/
		chart.getXYPlot().getRangeAxis().setRange(minvalue_,maxvalue_);
	}
		
	
	
	private JFreeChart createChart(XYDataset dataset_) {
			  if(dataset==null) return null; 
			  JFreeChart chart = ChartFactory.createXYLineChart(
			            titulo,      // chart title
			            "X",                      // x axis label
			            "Y",                      // y axis label
			            dataset,                  // data
			            PlotOrientation.VERTICAL,
			            true,                     // include legend
			            true,                     // tooltips
			            false                     // urls
			        );
			  return chart;
			  }
	private XYDataset createDataset(int recorte_) {
        
		XYSeriesCollection dataset = new XYSeriesCollection();	 
		XYSeries series1 = new XYSeries("Diario");
		XYSeries series2 = new XYSeries("-");
		XYSeries series3 = new XYSeries("Acumulado");
		
			
		barras_trade barrasa_ = new barras_trade();
		barrasa_.cargaSql("");
		Iterator<String> itr = barrasa_.fechas.iterator();
		int i=0;
		double acumulado=0;
		double benef_=0;
		while (itr.hasNext()) {
			String element=itr.next();
			if(!element.isEmpty()){
			isi_estudios estu1 =new isi_estudios(null,null,"",false);
			estu1.cargaSql(element);
			estu1.IniciaOscilador(14,3,7,1);
		//	benef_=estu1.CalculaBeneficios(recorte_);
			acumulado=acumulado+benef_;
			series1.add(i,benef_);
			series2.add(i,0);
			series3.add(i,acumulado);
			i++;
			}
			
		}
		
		dataset.addSeries(series1);		
		dataset.addSeries(series2);	
		dataset.addSeries(series3);	
			
			  return dataset;
			  }
}